
import { VxeGridPropTypes } from "vxe-table/types/grid";
import XEUtils from 'xe-utils';

export const columns: VxeGridPropTypes.Columns = [
  {type: 'checkbox', width: 40, fixed: 'left',},
  {type: 'seq', title: '序号', treeNode: false, visible: false, width: 60,},
  // {field: 'ID', title: 'ID', width: 60, visible: false,},
  {field: 'code', title: '编号', sortable: false, visible: true, minWidth: 80,},
  {field: 'name', title: '承运商名称', sortable: false, minWidth: 130,},
  {field: 'phone', title: '手机', sortable: false, width: 120,},
  {field: 'enable', title: '启用', sortable: false, width: 50, formatter: 'formatEnable',},
  {field: 'address', title: '地址', sortable: false, minWidth: 90,},
  {field: 'email', title: '电子邮件', sortable: false, visible: false, width: 90,},
  {field: 'bank', title: '开户银行', visible: false, sortable: false,},
  {field: 'bankNumber', title: '银行卡号', visible: false, sortable: false,},
  {field: 'telephone', title: '座机', visible: false, sortable: false, width: 80,},
  {field: 'memo', title: '备注', visible: true, sortable: false, minWidth: 90,},
  {field: 'creator.name', title: '创建人', sortable: false, visible: false, width: 90,},
  {field: 'CreatedAt', title: '创建时间', visible: false, sortable: true, width: 160,
  formatter ({ cellValue }) {
    return XEUtils.toDateString(cellValue,)
  }},
  {field: 'UpdatedAt', title: '更新时间', visible: false, sortable: false, width: 160, 
  formatter ({ cellValue }) {
    return XEUtils.toDateString(cellValue,)
  }},
];

/**
 * 迭代 禁用不可用的分类
 * @param parent 商品分类列表
 * @returns 
 */
export function deep(parent:any[]) {
  parent.forEach(e => {
    e.disabled = e.enable !== 1
    e.checked = false
    if (e.attrs && e.attrs.length > 0) {
      e.attrs.forEach(a => a.checked = false)
    }
    if (e.children && e.children.length > 0) deep(e.children)
  })
  return parent
}

